package com.EpidemicPrevention.controller;

import com.EpidemicPrevention.pojo.Enrolled;
import com.EpidemicPrevention.pojo.User;
import com.EpidemicPrevention.service.UserServiceImpl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


@Controller
@RequestMapping("/UserController")
public class UserController {

        @Autowired
        private UserServiceImpl userService;

        @GetMapping("/addUser")
        @ResponseBody
        @CrossOrigin
        public JSON addUser(User user) {
            return userService.addUser(user);
        }

        @GetMapping("/updataUser")
        @ResponseBody
        @CrossOrigin
        public  JSON updataUser(User user){ return userService. updateUser (user); }

        @GetMapping("/deleteUser")
        @ResponseBody
        @CrossOrigin
        public JSON deleteUser(int e_id) {
        return userService.deleteUser (e_id);
    }

        /**
         * 查看用户
         *
         * @param page
         * @param limit
         * @return
         */
        @GetMapping("/queryUser")
        @ResponseBody
        @CrossOrigin
        public JSON queryExceed(@RequestParam("page") int page, @RequestParam("limit") int limit) {
            JSONObject json = new JSONObject();
            int page1 = page - 1;
            int page2 = page1 * limit;
            json.put("code", 1);
            json.put("msg", "");
            json.put("count",userService.queryUser (0, 100000).size());
            json.put("data", userService.queryUser (page2, limit));
            return json;
        }



    }
